(in-package :lilu-mcclim-apropos)

;;;
;;;
;;;

(clim:define-presentation-type matched-command () :inherit-from '(matched-object))

(clim:define-presentation-method clim:present (object (type matched-command) stream
                                                      (view clim:textual-view)
                                                      &key acceptably for-context-type)
  (declare (ignore acceptably for-context-type))
  (let ((*package* (find-package :common-lisp-user)))
    (prin1 (climi::command-item-name object) stream)))
    #+nil(prin1 object stream)
  #+nil(princ (clim:command-name object) stream)

;;;
;;;
;;;


(clim:define-application-frame command-apropos-frame (iapropos-application-frame)
  ()
  (:default-initargs
   :iapropos (make-instance 'command-iapropos)
   :presentation-type 'matched-command
   :object-name "Command")
  (:command-table (command-apropos-frame-command-table
                   :inherit-from (iapropos-command-table
                                  iapropos-edit-command-table)
                   :menu (("Edit" :menu iapropos-edit-command-table)
                          ("Quit" :menu iapropos-command-table))))
  (:panes
   (command-result-display
    (make-ipropos-frame-matched-objects-pane))
   (command-output-display
    (make-ipropos-frame-selected-objects-pane))
   (matched-packages
    (make-ipropos-frame-matched-object-packages-pane))
   (command-name-regex-text-field
    (make-iapropos-frame-option-regex-pane :command-name-regex))
   (object-package-regex-text-field
    (make-iapropos-frame-option-regex-pane :command-package-name-regex))
   (command-table-regex-text-field
    (make-iapropos-frame-option-regex-pane :command-table-name-regex))
   (options
    (clim:labelling (:label "Selection")
      (make-iapropos-frame-selection-type-pane :orientation :vertical)))
   (actions (clim:labelling (:label "Actions")
              (make-iapropos-frame-action-pane))))
  (:layouts
   (:default
    (clim:vertically nil
      (3/5
       (clim:horizontally nil
         (clim:vertically nil
           options
           actions
           clim:+fill+)
         (clim:labelling (:label "Results")
           (clim:horizontally nil
             matched-packages
             command-result-display))))
      (2/5
       (clim:vertically nil
         (clim:labelling (:label "Output")
           command-output-display)
         (clim:labelling (:label "name regex" :align-x :center)
           command-name-regex-text-field)
         (clim:labelling (:label "command table regex" :align-x :center)
           command-table-regex-text-field)
         (clim:labelling (:label "package regex" :align-x :center)
           object-package-regex-text-field)
         ))))))

(defun run-command-apropos (&key (new-process nil)
                                    (width 790)
                                    (height 550)
                                    port
                                    frame-manager
                                    (pretty-name "Command Apropos")
                                    (process-name "command-apropos-frame"))
  (run-iapropos-application-frame 'command-apropos-frame
                                  :new-process new-process
                                  :width width
                                  :height height
                                  :port port
                                  :frame-manager frame-manager
                                  :pretty-name pretty-name
                                  :process-name process-name))
